package com.guigu.www.cxk.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.www.cxk.service.CXKHealthManagerService;
import com.guigu.www.mapper.ChatTableMapper;
import com.guigu.www.mapper.ConsultMessagesMapper;
import com.guigu.www.mapper.HealthManagerMapper;
import com.guigu.www.pojo.ChatTable;
import com.guigu.www.pojo.ConsultMessages;
import com.guigu.www.pojo.HealthManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CXKHealthManagerServiceImpl implements CXKHealthManagerService {

    @Autowired
    HealthManagerMapper healthManagerMapper;

    @Autowired
    ChatTableMapper  chatTableMapper;

    @Autowired
    ConsultMessagesMapper consultMessagesMapper;

    @Override
    public List<HealthManager> selectManager() {
        return healthManagerMapper.selectManager();
    }

    @Override
    public int saveChatTable(ChatTable chatTable) {
        return chatTableMapper.insert(chatTable);
    }

    @Override
    public ChatTable selectChatTable(int uid,int id) {
        QueryWrapper<ChatTable> chatTableQueryWrapper = new QueryWrapper<>();
        chatTableQueryWrapper.eq("mem_id",uid).eq("hm_id",id);
        return chatTableMapper.selectOne(chatTableQueryWrapper);
    }

    @Override
    public Integer addConsultMsg(Integer chatTaId, Integer conMesType, String conMesContent, Integer conMesState, String conMesAccount) {
        ChatTable chatTable = new ChatTable();
        chatTable.setChatTaId(chatTaId);
        chatTable.setChatTaState(0);
        chatTableMapper.updateById(chatTable);
        /*获取当前时间*/
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = dateFormat.format(date);
        ConsultMessages con = new ConsultMessages(null, chatTaId, conMesContent, conMesType, format, 0, 1, conMesAccount, conMesState);
        System.out.println(con);
        return consultMessagesMapper.insert(con);
    }
}

